package taller2.view.menus.MainEdittingMenus;

import java.awt.FlowLayout;
import java.awt.GridBagLayout;

import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.JToggleButton;

import taller2.controller.MainEdittingMenu.AreaMenuListener;
import taller2.controller.listeners.evaluateMeButtons.EvaluateMeButtonListener;
import taller2.interfaces.AlgorithmApplicator;
import taller2.interfaces.Graph;
import taller2.interfaces.MenuConBotones;
import taller2.utils.Point;
import taller2.utils.Utils;
import taller2.view.components.ResizeBar;
import taller2.view.draws.DrawingArea;
import taller2.view.windows.MainWindows.MainWindow;

public class MainEdittingMenu extends JPanel implements MenuConBotones{
	private static final long serialVersionUID = 1L;
	private JSlider graphSizeSelector;
	private JToggleButton changeGraphButton, evaluateMeButton;
	protected MainWindow window;
	protected ResizeBar bar;
	
	// constructor
	public MainEdittingMenu(MainWindow window, DrawingArea area, Graph graph, AlgorithmApplicator algorithmApplicator, EvaluateMeButtonListener evaluateMeListener) {
		this.window = window;
		evaluateMeListener.setMenu(this);
		
		
		JPanel pannel = new JPanel(new FlowLayout(FlowLayout.LEFT));
		
		AreaMenuListener listener = createAreaMenuListener(area,graph,this,algorithmApplicator);
		graphSizeSelector = new JSlider(10, 100);
		graphSizeSelector.addChangeListener(listener);
		pannel.add(graphSizeSelector);
		
		changeGraphButton = new JToggleButton("Edit Graph");
		changeGraphButton.addActionListener(listener);	
		pannel.add(changeGraphButton);
		
		evaluateMeButton = new JToggleButton("Evaluate Me");
		evaluateMeButton.addActionListener(evaluateMeListener);	
		pannel.add(evaluateMeButton);

		JPanel pannel2 = new JPanel(new FlowLayout(FlowLayout.LEFT));
		bar = new ResizeBar(this.window);
		pannel2.add(bar);
		
		setLayout(new GridBagLayout());
		Utils.addComponent(this,pannel,1, 0, new Point(0, 0));
		Utils.addComponent(this,pannel2,1, 0, new Point(0, 1));

/*		
		SaveAlgorithmListener listener2 = new SaveAlgorithmListener(graph,this,algorithmApplicator);
		loadAlgorithmButton = new JToggleButton("Save");
		loadAlgorithmButton.addActionListener(listener2);	
		add(loadAlgorithmButton);
		
		LoadAlgorithmListener listener3 = new LoadAlgorithmListener(graph,this,algorithmApplicator);
		saveAlgortihmButton = new JToggleButton("Load");
		saveAlgortihmButton.addActionListener(listener3);	
		add(saveAlgortihmButton);
*/
	}
	
	protected AreaMenuListener createAreaMenuListener(DrawingArea area,Graph graph, MainEdittingMenu edMenu,AlgorithmApplicator algorithmApplicator){
		return (new AreaMenuListener(this.window, area,graph,this,algorithmApplicator));
	}
	
    // unselects all buttons
    public void unselectButtons(){
    	changeGraphButton.setSelected(false);
    	evaluateMeButton.setSelected(false);
//    	loadAlgorithmButton.setSelected(false); 
//   	saveAlgortihmButton.setSelected(false); 
    }
    
}

